package com.bdqn.demo05;

/**
 * SingletonTest
 *
 * @author LILIBO
 * @since 2021-12-02
 */
public class TestSingleton {

    public static void main(String[] args) {
        // 测试单例模式（懒汉式）
        test01();

        // 测试单例模式（饿汉式）
        test02();
    }
    /**
     * 测试单例模式（懒汉式）
     */
    public static void test01() {
        Singleton01 singleton01 = Singleton01.getInstance();
        System.out.println(singleton01.count());
        // 一行一行的执行
        singleton01 = Singleton01.getInstance();
        singleton01 = Singleton01.getInstance();
        singleton01 = Singleton01.getInstance();
        singleton01 = Singleton01.getInstance();
        singleton01 = Singleton01.getInstance();

        System.out.println(singleton01.count());
    }

    /**
     * 测试单例模式（饿汉式）
     */
    public static void test02() {
        Singleton02 singleton02 = Singleton02.getInstance();
        System.out.println(singleton02.count());
        // 一行一行的执行
        singleton02 = Singleton02.getInstance();
        singleton02 = Singleton02.getInstance();
        singleton02 = Singleton02.getInstance();
        singleton02 = Singleton02.getInstance();
        singleton02 = Singleton02.getInstance();

        System.out.println(singleton02.count());
    }

}
